package com.ydj.app.controller;

import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.ydj.app.entity.CmsAccount;
import com.ydj.app.protocol.http.cms.CmsForecastExportListReq;
import com.ydj.app.protocol.http.cms.CmsForecastResultListReq;
import com.ydj.app.protocol.http.cms.CmsForecastResultListRes;
import com.ydj.app.protocol.http.cms.CmsKolExportExcelReq;
import com.ydj.app.service.ForecastService;
import com.ydj.framework.exception.CommonException;
import com.ydj.framework.filter.ExtHttpServletResponse;
import com.ydj.framework.protocol.JsonResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import java.io.IOException;

@RestController
@RequestMapping("/cms/forecast")
@Api(tags = "CMS-RWA预测")
public class CmsForecastController {

    @Autowired
    private ForecastService forecastService;

    @ResponseBody
    @ApiOperation(value = "获取用户提交的预测列表")
    @ApiOperationSupport(order = 10)
    @PostMapping(value = "/resultList")
    public JsonResult<CmsForecastResultListRes> resultList(@RequestBody @Validated CmsForecastResultListReq req, @ApiIgnore CmsAccount account) throws CommonException {
        CmsForecastResultListRes res = forecastService.cmsResultList(req, account);
        return JsonResult.success(res);
    }

    @ApiOperation(value = "导出Excel")
    @ApiOperationSupport(order = 60)
    @PostMapping(value = "/exportExcel")
    public JsonResult<?> exportExcel(@ApiIgnore ExtHttpServletResponse response, @RequestBody @Validated CmsForecastExportListReq req, @ApiIgnore CmsAccount account) throws CommonException, IOException {
        forecastService.cmsExportExcel(response, req, account);
        return JsonResult.success();
    }
}